ifdef SystemRoot # Windows
	RETURN = %errorlevel%
	PASS = echo "| PASS";set \a count=count+1;set \a total=total+1
	FAIL = echo "| FAIL";set \a total=total+1
	TRUE = IF $(RETURN) EQU 0 ($(PASS)) ELSE $(FAIL)
	FALSE = IF $(RETURN) EQU 0 ($(FAIL)) ELSE $(PASS)
	SILENT = NUL
	INIT = set count=0;set total=0
	RESULTS = echo "|==== Resultados:";echo "| "%count%"/"%total%
	CLASS_PATH = lib/jgrapht-jdk1.6.jar;lib/commons-cli-1.2.jar;.
	
else
	ifeq ($(shell uname), Linux) # Linux
		RETURN = $$?
		PASS = echo "| \033[1m\033[32mOK";export count=$$(echo $$count"+1"|bc);export total=$$(echo $$total"+1"|bc)
		FAIL = echo "| \033[1m\033[31mFAIL";export total=$$(echo $$total"+1"|bc)
		TRUE = if [ $(RETURN) -eq "0" ];then $(PASS) ;else $(FAIL);fi;echo "\033[0m|"
		FALSE = if [ $(RETURN) -eq "0" ];then $(FAIL);else $(PASS);fi;echo "\033[0m|"
		SILENT = "/dev/null"
		INIT = export count=0;export total=0
		RESULTS = echo "|==== Resultados:";echo "| "$$count"/"$$total
		CLASS_PATH = lib/jgrapht-jdk1.6.jar:lib/commons-cli-1.2.jar:.
	else
		TRUE = echo "?"
		FALSE = echo "?"
		SILENT = "log.txt"
	endif
endif

.SILENT:

all: java 
	javac -classpath $(CLASS_PATH) *.java

java:NetlistParser.jj
	javacc NetlistParser.jj

NetlistParser.jj:NetlistParser.jjt
	jjtree NetlistParser.jjt

clear:
	rm -rf *.class

clearall:clear
	rm -rf *.java
	rm -rf *.jj

# UNIT TESTS
# unittest(name,file,result)
unittest =								\
	echo "|===== TESTE $(1)"; \
	java -classpath $(CLASS_PATH) ../test_cases/$(2); $(3)

silentunittest =						\
	echo "|==== TESTE $(1)";		\
	java -classpath $(CLASS_PATH) ../test_cases/$(2) > $(SILENT) 2> $(SILENT); $(3)

test:
	$(INIT);\
	$(call unittest,fail,fail.isc,$(FALSE));\
	$(call unittest,fail 2,fail2.isc,$(FALSE));\
	$(call unittest,fail 3,fail3.isc,$(FALSE));\
	$(call unittest,c1,c1.isc,$(TRUE));\
	$(call unittest,c5,c5.isc,$(TRUE));\
	$(call unittest,c17,c17.isc,$(TRUE));\
	$(call unittest,c17a,c17a.isc,$(TRUE));\
	$(call unittest,c432,c432.isc,$(TRUE));\
	$(call unittest,c499,c499.isc,$(TRUE));\
	$(call unittest,c880a,c880a.isc,$(TRUE));\
	$(call unittest,c1355,c1355.isc,$(TRUE));\
	$(call unittest,c1355a,c1355a.isc,$(TRUE));\
	$(call unittest,c1908,c1908.isc,$(TRUE));\
	$(call unittest,c2670,c3540.isc,$(TRUE));\
	$(call unittest,c5315,c5315.isc,$(TRUE));\
	$(call unittest,c6288,c6288.isc,$(TRUE));\
	$(call unittest,c7552,c7552.isc,$(TRUE));\
	$(RESULTS)

silenttest:
	$(INIT);\
	$(call silentunittest,fail,fail.isc,$(FALSE));\
	$(call silentunittest,fail 2,fail2.isc,$(FALSE));\
	$(call silentunittest,fail 3,fail3.isc,$(FALSE));\
	$(call silentunittest,c1,c1.isc,$(TRUE));\
	$(call silentunittest,c5,c5.isc,$(TRUE));\
	$(call silentunittest,c17,c17.isc,$(TRUE));\
	$(call silentunittest,c17a,c17a.isc,$(TRUE));\
	$(call silentunittest,c432,c432.isc,$(TRUE));\
	$(call silentunittest,c499,c499.isc,$(TRUE));\
	$(call silentunittest,c880a,c880a.isc,$(TRUE));\
	$(call silentunittest,c1355,c1355.isc,$(TRUE));\
	$(call silentunittest,c1355a,c1355a.isc,$(TRUE));\
	$(call silentunittest,c1908,c1908.isc,$(TRUE));\
	$(call silentunittest,c2670,c3540.isc,$(TRUE));\
	$(call silentunittest,c5315,c5315.isc,$(TRUE));\
	$(call silentunittest,c6288,c6288.isc,$(TRUE));\
	$(call silentunittest,c7552,c7552.isc,$(TRUE));\
	$(RESULTS)

